package com.onlineshop.common.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.executor.BatchResult;

public interface GenericDao {

	public long generateSequence(String sqlNameWithNameSpace);

	public <T> int insertAndReturnAffectedCount(String sqlNameWithNameSpace, T obj);

	public <T> int insertAndSetupId(String sqlNameWithNameSpace, T obj);

	public int update(String sqlNameWithNameSpace, Map<String, Object> param);

	public int updateByObj(String sqlNameWithNameSpace, Object param);
	
	public int deleteByObj(String sqlNameWithNameSpace, Object param);
	
	public <T> T queryOne(String statement, long id);

	public <T> T queryOne(String statement, String idStr);

	public <T> T queryOne(String sqlNameWithNameSpace, Map<String, Object> map);

	public Object queryObject(String sqlNameWithNameSpace, Map<String, Object> map);

	@Deprecated
	/**
	 * deprecated因为不推荐悲观锁方式
	 * @param statement
	 * @param id
	 * @return
	 */
	public <T> T queryOneWithPessimisticLock(String statement, long id);

	public <T> T queryOneByObject(String sqlNameWithNameSpace, String mapKey, Object mapValue);

	public int queryCount(String sqlNameWithNameSpace, Map<String, Object> map);

	/**
	 * 因为 sun java编译器(javac)有个bug，会导致
	 * "int result = 泛型返回值的queryOne()"有编译错误，而eclipse编译器是正确的。
	 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954
	 * 所以增加这个没有泛型的queryInt()
	 * 
	 * @param sqlNameWithNameSpace
	 * @param map
	 * @return
	 */
	public int queryInt(String sqlNameWithNameSpace, Map<String, Object> map);

	public <T> List<T> queryList(String sqlNameWithNameSpace, Map<String, Object> map, DataPage<T> page);

	public <T> DataPage<T> queryPage(String countSqlNameWithNameSpace, String rsSqlNameWithNameSpace, Map<String, Object> map, DataPage<T> page);

	public <T> List<T> queryList(String sqlNameWithNameSpace, Map<String, Object> map);

	/**
	 * 此返回值定义在使用上比queryList()更灵活
	 * 
	 * @param sqlNameWithNameSpace
	 * @param map
	 * @return
	 */
	public <T> List<T> queryListByMap(String sqlNameWithNameSpace, Map<String, Object> map);

	public <T> List<T> queryList(String sqlNameWithNameSpace);

	public <T> List<T> queryIdIn(String sqlNameWithNameSpace, long[] idList);

	public <T> List<T> queryIdIn(String sqlNameWithNameSpace, String[] idList);

	public <K, V> Map<K, V> selectOneToMap(String sqlNameWithNameSpace, Map<K, V> param);

	public List<BatchResult> flushStatements();
}
